/*
 * Copyright 2019 bingoogolapple
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.bingoogolapple.transformerstip;

import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.utils.Color;
import ohos.agp.window.dialog.PopupDialog;
import ohos.app.Context;

/**
 * TransformersTip
 *
 * @author 王浩 邮件:bingoogolapple@gmail.com
 * @since 2021-04-25
 */
public class TransformersTip extends PopupDialog implements PopupDialog.DialogListener {
    private Component mContentView; // 浮窗内容视图

    /**
     * 锚点控件
     *
     * @param anchorView 锚点控件
     * @param contentView 浮窗内容视图
     */
    public TransformersTip(Component anchorView, Component contentView) {
        super(anchorView.getContext(), anchorView);
        mContentView = contentView;
        setCustomComponent(mContentView);
        initView(contentView);
    }

    /**
     * 锚点控件
     *
     * @param anchorView 锚点控件
     * @param layoutResId 浮窗布局资源 id
     */
    public TransformersTip(Component anchorView, int layoutResId) {
        super((Context) anchorView, LayoutScatter.getInstance(anchorView.getContext()).parse(layoutResId, null, false));
    }

    /**
     * 初始化控件
     *
     * @param contentView contentView 控件
     */
    protected void initView(Component contentView) {
    }

    /**
     * 设置背景色
     *
     * @param value 颜色
     */
    public void setBgColor(Color value) {
        super.setBackColor(value);
    }

    /**
     * 设置箭头高度
     *
     * @param width 宽
     * @param height 高
     */
    public void setArrowSize(int width, int height) {
        super.setArrowSize(width, height);
    }

    /**
     * 设置浮窗圆角半径
     *
     * @param value 圆角半径
     */
    public void setRadiusRes(int value) {
        super.setCornerRadius(value);
    }

    /**
     * 设置箭头相对于浮窗的位置
     *
     * @param gravity 对其方式
     * @return PopupDialog
     */
    public PopupDialog setMode(int gravity) {
        super.setMode(gravity);
        return this;
    }

    /**
     * 关闭浮窗
     */
    public void dismissTip() {
        super.destroy();
    }

    /**
     * 显示浮窗
     */
    public void showDialog() {
        show();
    }

    @Override
    public boolean isTouchOutside() {
        return false;
    }
}
